/**  
  -- The Performance Driven Lime Project -- 

  A self adaptive tuple space for mobile agents and hosts by dynamic
  adapting tuple's replication policy.
  
  Copyright (C) 2008
  Xing Jiankuan, Pan Wenhui
  SAGroup of Tsinghua University

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
package sagroup.dracots.testing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

/**
 * This is a kind of components in dashboard, in which:
 * The border is a titled line border with specific title
 * Top right is a "Refresh" button 
 * Bottom is a scrolled pane for list output
 * 
 * *************************************************************************
 * To use this basic dashboard in you UI, you just need to :
 * 1. Define a BasicDashboard object with "new BasicDashboard(String title)"
 * 2. Define a method to fill the BasicDashboard.listModel;
 * 3. Define addActionListener derived class to handle the "refresh" button
 * 	  In addition, this class must have a constructor with the 
 * 	  BasicDashboard.listModel as input
 * 4. Add the clss above to the "refresh" button
 * **************************************************************************
 * 
 * @author Jinxue Zhang
 * 
 */
public class BasicDashboard extends JPanel {

	private static final long serialVersionUID = -3613554346247580863L;

	private JButton button = new JButton("Refresh");

	private myTitledBorder titledBorder = null;

	private JScrollPane scrollPane = null;

	private DefaultListModel listModel = null;

//	BasicDashboard(myTitledBorder titledBorder) {
//		this.titledBorder = titledBorder;
//		this.listModel = new DefaultListModel();
//		this.scrollPane = new JScrollPane(new JList(listModel));
//		this.setLayout(new BorderLayout());
//		this.setBorder(titledBorder);
//		this.add(BorderLayout.NORTH, button);
//		this.add(BorderLayout.CENTER, scrollPane);
//	}

	BasicDashboard(String title) {
		this.titledBorder = new myTitledBorder(title);
		this.listModel = new DefaultListModel();
		this.scrollPane = new JScrollPane(new JList(listModel));

		this.setLayout(new BorderLayout());
		this.setBorder(titledBorder);
		JPanel buttonPanel = new JPanel(new FlowLayout());
		buttonPanel.add(button);
		this.add(BorderLayout.NORTH, buttonPanel);
		this.add(BorderLayout.CENTER, scrollPane);

	}

	public JButton getRefreshButton() {
		return button;
	}

	public DefaultListModel getListModel() {
		return listModel;
	}

	/*
	 * The titled line border
	 */
	private class myTitledBorder extends TitledBorder {

		/**
		 * 
		 */
		private static final long serialVersionUID = -3197986460356089025L;

		public myTitledBorder(String title) {
			// TODO Auto-generated constructor stub
			super(new LineBorder(Color.ORANGE, 2), title);
			this.setTitleFont(new Font("Tohama", Font.PLAIN, 16));
			this.setTitleColor(Color.MAGENTA);
		}
	}

}
